package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.Score_component;

public class ScoreMod {
	Connection connection;
	public static ScoreMod isntanceSM;
	public static ScoreMod getIsntance(){
		if(isntanceSM == null){
			isntanceSM = new ScoreMod();
		}
		return isntanceSM;
	}
	public boolean addSCP(Score_component sc){
		boolean result = false;
		PreparedStatement sqli = null;
		connection = DB_Connection.getIsntance().getConnection();
		try {
			String sql = "INSERT INTO score_component_1 (sid, sjid, scholastic, half, number, oral_test, minute_15, minute_45) " +
					"VALUES( ? , ? , ? , ? , ? , ? , ? , ? )";
			sqli = connection.prepareStatement(sql);
			sqli.setInt(1, sc.getSid());
			sqli.setInt(2, sc.getSjid());
			sqli.setString(3, sc.getScholastic());
			sqli.setInt(4, sc.getHalf());
			sqli.setInt(5, sc.getNumber());
			sqli.setFloat(6, sc.getOral_test());
			sqli.setFloat(7, sc.getMinute_15());
			sqli.setFloat(8, sc.getMinute_45());
			int n = sqli.executeUpdate();
			if( n > 0) result = true;
			sqli.close();
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public Score_component getSCP(Score_component sc){
		Score_component result = null;
		connection = DB_Connection.getIsntance().getConnection();
		PreparedStatement sqls = null;
		try {
			String sql = "SELECT * FROM score_component WHERE sid = ? AND sjid = ? AND scholastic = ? AND half = ? AND number = ? ";
			sqls =connection.prepareStatement(sql);
			sqls.setInt(1, sc.getSid());
			sqls.setInt(2, sc.getSjid());
			sqls.setString(3, sc.getScholastic());
			sqls.setInt(4, sc.getHalf());
			sqls.setInt(5, sc.getNumber());
			ResultSet rs = sqls.executeQuery();
			while(rs.next()){
				result = new Score_component(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getInt(5), rs.getInt(6), rs.getFloat(7), rs.getFloat(8), rs.getFloat(9));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public boolean addOralTest(Score_component sc){
		boolean result = false;
		
		return result;
	}
	public boolean add15(Score_component sc){
		boolean result = false;
		
		return result;
	}
	public boolean add45(Score_component sc){
		boolean result = false;
		
		return result;
	}
	public boolean UpdateOralTest(Score_component sc){
		boolean result = false;
		connection = DB_Connection.getIsntance().getConnection();
		PreparedStatement sqls = null;
		try {
			String sql = "UPDATE score_component SET  WHERE sid = ? AND sjid = ? AND scholastic = ? AND half = ? AND number = ? ";
			sqls =connection.prepareStatement(sql);
			sqls.setInt(1, sc.getSid());
			sqls.setInt(2, sc.getSjid());
			sqls.setString(3, sc.getScholastic());
			sqls.setInt(4, sc.getHalf());
			sqls.setInt(5, sc.getNumber());
			ResultSet rs = sqls.executeQuery();
			while(rs.next()){
		
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public boolean Update15(Score_component sc){
		boolean result = false;
		
		return result;
	}
	public boolean Update45(Score_component sc){
		boolean result = false;
		
		return result;
	}
}
